# Please install OpenAI SDK first: `pip3 install openai`

from openai import OpenAI

client = OpenAI(api_key="sk-8d1b4abc924c45ad8ee63d37d1e95c9c", base_url="https://api.deepseek.com")

while True:
    question = input("请输入您的问题：")
    response = client.chat.completions.create(
        model="deepseek-chat",
        messages=[
            {"role": "system", "content": "You are a helpful assistant"},
            {"role": "user", "content": question},
        ],
        stream=True
    )
    # 流式响应处理
    full_response = ""
    for chunk in response:
        if chunk.choices[0].delta.content:
            full_response += chunk.choices[0].delta.content
            # 逐字实时打印（可选）
            print(chunk.choices[0].delta.content, end="", flush=True)
    
    # # 打印完整响应并换行（如果不需要实时显示可只保留这个）
    # print("\n" + full_response)
